﻿package com.alpheus.net.js
{
	/**
	 * Js通信类
	 */ 

	
	import com.alpheus.util.Logger;
	
	import flash.external.ExternalInterface;
	import flash.system.Capabilities;

	public class JsConnection 
	{
		
		private static var instance:JsConnection;
		
		public function JsConnection()
		{
			ExternalInterface.addCallback('callMethod', callMethod);
		}
		
		/**
		 *获取JsConnection实例
		 * @return 
		 * 
		 */		
		public static function getInstance():JsConnection
		{
			if (instance == null) instance = new JsConnection();
			return instance;
		}
		
		/**
		 * 调用外部Js方法
		 * @param method
		 * @param args
		 * @return 
		 * 
		 */		
		public function callJS(method : String, ...args):* {
			Logger.logInfo("JS flash-web:",method,args.toString());
			if (Capabilities.playerType == "StandAlone") return null;
			if(args.length==2)
				return ExternalInterface.call(method,args[0],args[1]);	
			else if(args.length==3)	
				return ExternalInterface.call(method,args[0],args[1],args[2]);	
			else
				return ExternalInterface.call(method,args);				
		}
		
		
		/**
		 * Js调用flash方法
		 * @param method
		 * @param args
		 * 
		 */		
		public function callMethod(method:String, args:Array = null):void {		
			if (args) {
				Logger.logInfo("JS web-flash:",method,args.toString());
			}else 
				Logger.logInfo("JS web-flash:",method);
			
			var urlName:String = "";
			var place:int = 1;		
			//var dataParam:DataParamVO;
			//var userProxy:UserProxy;
			switch(method)
			{					
				
				
				
			}			
		}		
	}	
}